package com.aaa.constant;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 杨森
 * @version 1.0
 * @Title:
 * @date 2020/9/17 15:46
 */
public class DataSource {
    private static Map<String, List<String>> listMap=new HashMap<>();
    static {
        List<String> list=new ArrayList<>();
        list.add(0,"GET--https://www.biquge5200.com/modules/article/search.php?searchkey=");
        List<String> list1 = new ArrayList<>();
        list1.add(0,"POST--http://www.ddxs.com/search.php");
        listMap.put("ddxs",list1);
//        listMap.put("biquge5200",list);
    }
    static {
        File file=new File("C:\\Program Files\\SanMuYuan\\dataSource.txt");
        InputStreamReader reader= null;
        try {
            reader = new InputStreamReader(new FileInputStream(file));
            BufferedReader br=new BufferedReader(reader);
            String str;
            while ((str = br.readLine()) != null) {
                String[] split = str.split("--");
                List<String> list=new ArrayList<>();
                list.add(0,split[1]+"--"+split[2]);
                listMap.put(split[0],list);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static Map<String, List<String>> getDataSource(String data) throws Exception {
        if(listMap.get(data)==null){
            DataSource.setDataSource(data);


        }
        return listMap;
    }

    private static void setDataSource(String dataSource) throws Exception {
        File file=new File("C:\\Program Files\\SanMuYuan");
        if(!file.exists()){
            file.mkdir();
            System.out.println("在C:\\Program Files创建目录SanMuYuan");
        }
        file=new File("C:\\Program Files\\SanMuYuan\\dataSource.txt");
        if(!file.exists()){
            file.createNewFile();
        }
        OutputStreamWriter read = new OutputStreamWriter(
                new FileOutputStream(file));
        BufferedWriter bw=new BufferedWriter(read);
        bw.write(dataSource);
        bw.close();
    }

    public static void main(String[] args) {
        System.out.println(listMap.get("biquge5200"));
    }
}
